package com.qiaotongtianxia.loans.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.qiaotongtianxia.loans.R;
import com.qiaotongtianxia.loans.functionInterface.IBaseRequestImp;
import com.qiaotongtianxia.loans.net.Api;
import com.qiaotongtianxia.loans.util.CommonUtils;
import com.qiaotongtianxia.loans.util.Constants;
import com.qiaotongtianxia.loans.util.ToastUtil;
import com.qiaotongtianxia.loans.views.BaseTextView;
import com.qiaotongtianxia.loans.views.ButtonObserver;
import com.qiaotongtianxia.loans.views.DragLayout;
import com.qiaotongtianxia.loans.views.dialogs.ItemsDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lisen on 2017/12/16.
 * 直接借款页面
 *
 * @author lisen < 4533548588@qq.com >
 */

public class DirectLoansActivity extends BaseActivity {
    @BindView(R.id.tv_nav_title)
    BaseTextView tvNavTitle;
    @BindView(R.id.tv_notice)
    BaseTextView tv_notice;
    @BindView(R.id.btn_loans)
    ButtonObserver btnLoans;
    @BindView(R.id.tv_amount)
    BaseTextView tvAmount;
    @BindView(R.id.dragLayout)
    DragLayout dragLayout;

    private String loansAmount;

    @Override
    public int getLayoutId() {
        return R.layout.activity_direct_loans;
    }

    @Override
    public Api onApiCreate() {
        return new Api(this);
    }

    @Override
    public void onBaseCreate(@Nullable Bundle savedInstanceState) {
        btnLoans.setExtraEnable(true);
        loansAmount = getIntent().getStringExtra(Constants.LOANS_AMOUNT);
        tvAmount.setText(loansAmount);
        tvAmount.setTag(loansAmount);
        tv_notice.setFocusableInTouchMode(true);
        tv_notice.requestFocus();
    }

    @OnClick({R.id.iv_nav_back,R.id.layout_chooseAmount, R.id.btn_loans})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_nav_back:
                finish();
                break;
            case R.id.layout_chooseAmount:
                ItemsDialog.Buidler buidler = new ItemsDialog.Buidler(DirectLoansActivity.this);
                for (int i = 0; i < 41; i++) {
                    buidler.addItem((100 * i+1000)+"",(100 * i+1000)+"");
                }
                buidler.setDialogHeight(CommonUtils.getScreenHeight(DirectLoansActivity.this)/2);
                buidler.setSimpleListener(new ItemsDialog.SimpleSheetListener() {
                    @Override
                    public void onSheetItemClick(int position, ItemsDialog.ItemBean itemBean) {
                        tvAmount.setText(itemBean.getName());
                        tvAmount.setTag(itemBean.getT().toString());
                    }
                });
                buidler.build();
                break;
            case R.id.btn_loans:
                api.directLoans(tvAmount.getTag().toString(), new IBaseRequestImp<String>() {
                    @Override
                    public void onRequestSuccess(String s) {
                        ToastUtil.showShort(DirectLoansActivity.this,s);
                        finish();
                    }
                });
                break;
        }
    }

    @Override
    public void initTitle() {
        tvNavTitle.setText(getString(R.string.loans));
    }

}
